package org.toools.gwt.wmc.jpa;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.Vector;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author stefan asseg
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Waste.getAll", query = "SELECT w FROM Waste w"),
    @NamedQuery(name = "Waste.getById", query = "SELECT w FROM Waste w WHERE w.gtin = :id")
})
public class Waste implements Serializable, com.google.gwt.user.client.rpc.IsSerializable {

    @Id
    private Integer gtin;
    private Integer waste;
    private Integer spec;
    private String wasteDesc;
    private String specDesc;
    private String criticality;
    private String critical_key;
    private String typeCriticalKey;
    private String nonCriticalKey;
    private String typeNonCriticalKey;
    private String comment;
    @Temporal(TemporalType.DATE)
    private Date validFrom;
    @Temporal(TemporalType.DATE)
    private Date validTo;
    @ManyToMany( fetch=FetchType.EAGER )
    private Collection<Container> containers = new Vector<Container>();

    public Waste() {
    }

    public Waste(Integer gtin) {
        this.gtin = gtin;
    }

    public Waste(Integer gtin, String comment) {
        this.gtin = gtin;
        this.comment = comment;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getCritical_key() {
        return critical_key;
    }

    public void setCritical_key(String critical_key) {
        this.critical_key = critical_key;
    }

    public String getCriticality() {
        return criticality;
    }

    public void setCriticality(String criticality) {
        this.criticality = criticality;
    }

    public Integer getGtin() {
        return gtin;
    }

    public void setGtin(Integer gtin) {
        this.gtin = gtin;
    }

    public String getNonCriticalKey() {
        return nonCriticalKey;
    }

    public void setNonCriticalKey(String nonCriticalKey) {
        this.nonCriticalKey = nonCriticalKey;
    }

    public Integer getSpec() {
        return spec;
    }

    public void setSpec(Integer spec) {
        this.spec = spec;
    }

    public String getSpecDesc() {
        return specDesc;
    }

    public void setSpecDesc(String specDesc) {
        this.specDesc = specDesc;
    }

    public String getTypeCriticalKey() {
        return typeCriticalKey;
    }

    public void setTypeCriticalKey(String typeCriticalKey) {
        this.typeCriticalKey = typeCriticalKey;
    }

    public String getTypeNonCriticalKey() {
        return typeNonCriticalKey;
    }

    public void setTypeNonCriticalKey(String typeNonCriticalKey) {
        this.typeNonCriticalKey = typeNonCriticalKey;
    }

    public Date getValidFrom() {
        return validFrom;
    }

    public void setValidFrom(Date validFrom) {
        this.validFrom = validFrom;
    }

    public Date getValidTo() {
        return validTo;
    }

    public void setValidTo(Date validTo) {
        this.validTo = validTo;
    }

    public Integer getWaste() {
        return waste;
    }

    public void setWaste(Integer waste) {
        this.waste = waste;
    }

    public String getWasteDesc() {
        return wasteDesc;
    }

    public void setWasteDesc(String wasteDesc) {
        this.wasteDesc = wasteDesc;
    }

    public Collection<Container> getContainers() {
        return containers;
    }

    public void setContainers(Collection<Container> containers) {
        this.containers = containers;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (gtin != null ? gtin.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the gtin fields are not set
        if (!(object instanceof Waste)) {
            return false;
        }
        Waste other = (Waste) object;
        if ((this.gtin == null && other.gtin != null) || (this.gtin != null && !this.gtin.equals(other.gtin))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Waste [gtin = " + gtin + "]";
    }
}
